#-*- codeing = utf-8 -*-
#@Time : 2020/8/9 14:08
#@Author : 阳某
#@File : selenium操作滚动条.py
#@Software : PyCharm

'''
# 竖向滚动条拉到底部    scrollTop   0是最上面，，10000是最底部
js = 'var q=document.documentElement.scrollTop=10000'
js = 'var q=document.body.scrollTop=0'
driver.execute_script(js)
'''
'''
横向拉滚动条（通过左边控制横向和纵向滚动条scrollTo（x，y））
js = "window.scrollTo(100,400)"
driver.execute_script(js)
'''
from selenium import webdriver
from lxml import etree
from time import sleep
url = 'https://search.jd.com/Search?keyword=mac&enc=utf-8&wq=mac&pvid=ad1cc2b00f6549adb3697abd5c6c81f0'

driver  = webdriver.Chrome()
driver.maximize_window()
driver.get(url)



js = 'var q=document.documentElement.scrollTop=10000'
driver.execute_script(js)

sleep(3)

html = driver.page_source
# print(html)
e = etree.HTML(html)
prices = e.xpath('//div[@class="gl-i-wrap"]/div[@class="p-price"]/strong/i/text()')
names = e.xpath('//div[@class="gl-i-wrap"]/div[@class="p-name p-name-type-2"]/a/em')
print((len(names)))

for name,price in zip(names,prices):
    print(name.xpath('string(.)'),':',price)













